<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="工号" prop="jobId">
        <el-input
          v-model="queryParams.jobId"
          placeholder="请输入工号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> <br/>
      <el-form-item label="专案名称" prop="projectName">
        <el-select v-model="queryParams.projectName" placeholder="请选择专案名称" clearable size="small">
          <el-option label="专案选项" value="" />
          <el-option label="选项 2" value="选项 2" />
          <el-option label="选项 3" value="选项 3" />
          <el-option label="选项 4" value="选项 4" />
        </el-select>
      </el-form-item> <br/>
      <el-form-item label="FTP账号" prop="ftpAccountNumber">
        <el-input
          v-model="queryParams.ftpAccountNumber"
          placeholder="请输入FTP账号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['info:ftpMgmt:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['info:ftpMgmt:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['info:ftpMgmt:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['info:ftpMgmt:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ftpMgmtList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="ftpId" />
      <el-table-column label="工号" align="center" prop="jobId" />
      <el-table-column label="账户" align="center" prop="account" />
      <el-table-column label="账户名称" align="center" prop="accountName" />
      <el-table-column label="部门" align="center" prop="derpartment" />
      <el-table-column label="目录" align="center" prop="catalog" />
      <el-table-column label="上传(0无,1有)" align="center" prop="upload" />
      <el-table-column label="下载(0无,1有)" align="center" prop="download" />
      <el-table-column label="专案名称" align="center" prop="projectName" />
      <el-table-column label="有效期" align="center" prop="validity" />
      <el-table-column label="期限" align="center" prop="deadine" />
      <el-table-column label="编辑" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['info:ftpMgmt:edit']"
          >编辑</el-button>
        </template>
      </el-table-column>
      <el-table-column label="删除" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['info:ftpMgmt:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改FTP账户管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="工号" prop="jobId">
          <el-input v-model="form.jobId" placeholder="请输入工号" />
        </el-form-item>
        <el-form-item label="账户" prop="account">
          <el-input v-model="form.account" placeholder="请输入账户" />
        </el-form-item>
        <el-form-item label="账户名称" prop="accountName">
          <el-input v-model="form.accountName" placeholder="请输入账户名称" />
        </el-form-item>
        <el-form-item label="部门" prop="derpartment">
          <el-input v-model="form.derpartment" placeholder="请输入部门" />
        </el-form-item>
        <el-form-item label="目录" prop="catalog">
          <el-input v-model="form.catalog" placeholder="请输入目录" />
        </el-form-item>
        <el-form-item label="上传(0无,1有)" prop="upload">
          <el-input v-model="form.upload" placeholder="请输入上传(0无,1有)" />
        </el-form-item>
        <el-form-item label="下载(0无,1有)" prop="download">
          <el-input v-model="form.download" placeholder="请输入下载(0无,1有)" />
        </el-form-item>
        <el-form-item label="专案名称" prop="projectName">
          <el-select v-model="form.projectName" placeholder="请选择专案名称">
            <el-option label="专案选项" value="" />
            <el-option label="选项 2" value="选项 2" />
            <el-option label="选项 3" value="选项 3" />
            <el-option label="选项 4" value="选项 4" />
          </el-select>
        </el-form-item>
        <el-form-item label="有效期" prop="validity">
          <el-input v-model="form.validity" placeholder="请输入有效期" />
        </el-form-item>
        <el-form-item label="期限" prop="deadine">
          <el-input v-model="form.deadine" placeholder="请输入期限" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFtpMgmt, getFtpMgmt, delFtpMgmt, addFtpMgmt, updateFtpMgmt, exportFtpMgmt } from "@/api/info/ftpMgmt";

export default {
  name: "FtpMgmt",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // FTP账户管理表格数据
      ftpMgmtList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        jobId: null,
        ftpAccountNumber: null,
        state: null,
        account: null,
        accountName: null,
        derpartment: null,
        catalog: null,
        upload: null,
        download: null,
        projectName: null,
        validity: null,
        deadine: null,
        creatorName: null,
        creatorId: null,
        updateName: null,
        updateId: null,
        reserved: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询FTP账户管理列表 */
    getList() {
      this.loading = true;
      listFtpMgmt(this.queryParams).then(response => {
        this.ftpMgmtList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ftpId: null,
        jobId: null,
        ftpAccountNumber: null,
        state: null,
        account: null,
        accountName: null,
        derpartment: null,
        catalog: null,
        upload: null,
        download: null,
        projectName: null,
        validity: null,
        deadine: null,
        creatorName: null,
        creatorId: null,
        createTime: null,
        updateName: null,
        updateId: null,
        updateTime: null,
        reserved: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.ftpId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加FTP账户管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const ftpId = row.ftpId || this.ids
      getFtpMgmt(ftpId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改FTP账户管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.ftpId != null) {
            updateFtpMgmt(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFtpMgmt(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ftpIds = row.ftpId || this.ids;
      this.$modal.confirm('是否确认删除FTP账户管理编号为"' + ftpIds + '"的数据项？').then(function() {
        return delFtpMgmt(ftpIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有FTP账户管理数据项？').then(() => {
        this.exportLoading = true;
        return exportFtpMgmt(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
